package com.sc.nft.controller;

import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.IdRequest;
import com.sc.nft.entity.vo.AppArticleListVO;
import com.sc.nft.entity.vo.AppByIdArticleVO;
import com.sc.nft.service.InformationArticleService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/article")
@Api(tags = "文章")
public class ArticleController {

    private final InformationArticleService informationArticleService;

    @ApiOperation(value = "获取文章列表", notes = "获取文章列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getArticleList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<AppArticleListVO>> getArticleList(@RequestBody PageRequest pageRequest) {
        return Result.success(informationArticleService.getArticleList(pageRequest));
    }

    @ApiOperation(value = "获取文章详情", notes = "获取文章详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getArticleDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<AppByIdArticleVO> getArticleDetails(@RequestBody IdRequest idRequest) {
        return Result.success(informationArticleService.getArticleDetails(idRequest.getId()));
    }

    @ApiOperation(value = "获取最新5条,抛出当前的条目", notes = "获取最新5条,抛出当前的条目", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getLimitFive", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<AppByIdArticleVO>> getLimitFive(@RequestBody IdRequest idRequest) {
        return Result.success(informationArticleService.getLimitFive(idRequest.getId()));
    }

}
